<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>微信登录</title>

    <script src="js/plugins/vue/dist/vue.js"></script>
    <script src="js/plugins/axios/dist/axios.js"></script>
    <script src="js/common.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
</head>
<body>
    <div id="app"></div>
</body>

<script>
    new Vue ({
        el: '#app',
        mounted() {
            var url = location.href
            var code = param2JsonObj(url).code
            this.$http.get("/login/wechat/"+code).then(res => {
                if (res.data.success) {
                    let {token, logininfo} = res.data.resultObj;
                    localStorage.setItem("token", token)
                    localStorage.setItem("logininfo", JSON.stringify(logininfo))
                    this.$notify({
                        title: '成功',
                        duration: 2000,
                        showClose: true,
                        message: res.data.msg,
                        type: 'success'
                    });
                    let timer = setTimeout(() => {
                        //需要定时执行的代码
                        window.location.href = '/index.html'
                    }, 500)
                } else {
                    let {access_token, openid} = res.data.resultObj;
                    localStorage.setItem("access_token", access_token)
                    localStorage.setItem("openid", openid)
                    this.$notify({
                        title: '提示',
                        duration: 2000,
                        showClose: true,
                        message: res.data.msg,
                        type: 'warning'
                    });
                    let timer = setTimeout(() => {
                        //需要定时执行的代码
                        window.location.href = '/binder.html?access_token='+access_token+'&openid='+openid
                    }, 500)
                }
            }).catch(res => {

            })
        },
    })
</script>
</html>
